#include "stdafx.h"
#include "HUD.h"
#include "VertexBuffer.h"

#include "..\EdgeContent\ContentManager.h"
#include "..\EdgeMath\VectorHelper.h"
#include "..\EdgeMath\Math.h"
#include "..\EdgeGameCore\SettingsManager.h"
#include "..\EdgeGraphics\Texture2D.h"

using namespace VertexFormats;

Hud::Hud(void)
{
	screenQuad = new ScreenQuad();
}

/*virtual*/ Hud::~Hud(void)
{
	delete screenQuad;
}


void Hud::DrawRectangle(int x, int y, int width, int height, Vector4 color)
{
	static float SCR_WIDTH = (float)SettingsManager::GetInstance()->getSetting("ScreenWidth")._int;
	static float SCR_HEIGHT = (float)SettingsManager::GetInstance()->getSetting("ScreenHeight")._int;
	float left = float(x);
	float right = float(x + width);
	float top = float(y);
	float bottom = float(y + height);

	// some values to define where this point is in screen coodinates
	float scr_width_2 = SCR_WIDTH / 2.f;
	float scr_height_2 = SCR_HEIGHT / 2.F;
	float xAt = (x - scr_width_2) / scr_width_2;
	float yAt = -((y - scr_height_2) / scr_height_2);
	float rightAt = (right - scr_width_2) / scr_width_2;
	float bottomAt = -((bottom - scr_height_2) / scr_height_2);

	screenQuad->setBounds(Box2D(xAt, rightAt, yAt, bottomAt));
	screenQuad->setUseTexture(false);
	screenQuad->setColor(color);
	screenQuad->setTexRegion(Box2D(vector_2::Zero, 1, 1));
	
	screenQuad->Draw();
}


void Hud::DrawRectangle(int x, int y, int width, int height, IGraphicsResource* texture, Vector4 color)
{
	static float SCR_WIDTH = (float)SettingsManager::GetInstance()->getSetting("ScreenWidth")._int;
	static float SCR_HEIGHT = (float)SettingsManager::GetInstance()->getSetting("ScreenHeight")._int;
	float left = float(x);
	float right = float(x + width);
	float top = float(y);
	float bottom = float(y + height);

	screenQuad->setResourceView(texture, 0);

	// some values to define where this point is in screen coodinates
	float scr_width_2 = SCR_WIDTH / 2.f;
	float scr_height_2 = SCR_HEIGHT / 2.F;
	float xAt = (x - scr_width_2) / scr_width_2;
	float yAt = -((y - scr_height_2) / scr_height_2);
	float rightAt = (right - scr_width_2) / scr_width_2;
	float bottomAt = -((bottom - scr_height_2) / scr_height_2);

	screenQuad->setBounds(Box2D(xAt, rightAt, yAt, bottomAt));
	screenQuad->setTexRegion({ 0.f, 1.f, 0.f, 1.f });
	screenQuad->setUseTexture(true);
	screenQuad->setColor(color);

	screenQuad->Draw();
}


void Hud::DrawRectangle(int x, int y, int width, int height, RECT_F region, IGraphicsResource* texture, Vector4 color)
{
	static float SCR_WIDTH =  (float)SettingsManager::GetInstance()->getSetting("ScreenWidth")._int;
	static float SCR_HEIGHT = (float)SettingsManager::GetInstance()->getSetting("ScreenHeight")._int;
	float left = float(x);
	float right = float(x + width);
	float top = float(y);
	float bottom = float(y + height);

	screenQuad->setResourceView(texture, 0);

	// some values to define where this point is in screen coodinates
	float scr_width_2 = SCR_WIDTH / 2.f;
	float scr_height_2 = SCR_HEIGHT / 2.F;
	float xAt = (x - scr_width_2) / scr_width_2;
	float yAt = -((y - scr_height_2) / scr_height_2);
	float rightAt = (right - scr_width_2) / scr_width_2;
	float bottomAt = -((bottom - scr_height_2) / scr_height_2);

	screenQuad->setBounds(Box2D(xAt, rightAt, yAt, bottomAt));
	screenQuad->setTexRegion(region);
	screenQuad->setUseTexture(true);
	screenQuad->setColor(color);
	
	screenQuad->Draw();
}